# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#   
#   cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
#   Major.create(:name => 'Daley', :city => cities.first)

#reating General Settings
GeneralSetting.delete_all
GeneralSetting.create!(:id => 1,
                      :org_name => 'Jarvis Demo School',
                      :org_tagline => 'A sample demo school setup')

#Loading countries
Country.delete_all
open("#{Rails.root}/Public/seeds/countries.csv") do |countries|
  countries.read.each_line do |country|
    name, capital, curr_code, curr_name, tel_code, code_2, code_3, num, tld = country.split(",")
    Country.create!(:name => name,
                    :capital => capital,
                    :currency_code => curr_code,
                    :currency_name => curr_name,
                    :telephone_code => tel_code,
                    :country_code_2 => code_2,
                    :country_code_3 => code_3,
                    :country_number => num,
                    :country_tld => tld)
  end
end

#Loading TimeZones
Timezone.delete_all
open("#{Rails.root}/Public/seeds/timezones.csv") do |tzones|
  tzones.read.each_line do |tzone|
    code, name, wrt_gmt = tzone.split(",")
    Timezone.create!( :code => code,
                      :name => name, 
                      :wrt_gmt => wrt_gmt)
  end
end

#Loading some Sample Batches
Batch.delete_all
open("#{Rails.root}/Public/seeds/batches.csv") do |batches|
  batches.read.each_line do |batch|
    name, parent, st_dt, end_dt = batch.split(",")
    Batch.create!(  :code => name.downcase,
                    :name => name,
                    :parent_batch_id => parent,
                    :start_date => st_dt,
                    :end_date => end_dt)
  end
end

#Loading some Sample Course
Course.delete_all
open("#{Rails.root}/Public/seeds/courses.csv") do |courses|
  courses.read.each_line do |course|
    name, parent, st_dt, end_dt = course.split(",")
    Course.create!(  :code => name.downcase,
                    :name => name,
                    :parent_batch_id => parent,
                    :parent_course_id => parent,
                    :start_date => st_dt,
                    :end_date => end_dt)
  end
end